import axios from 'axios'
import apiUrls from 'common/api-urls'

export function uploadFile(data) {
  const formData = new FormData()
  formData.append('files', data.file.raw)
  if (data.busiType) {
    formData.append('busiType', data.busiType)
  }
  return axios.post(apiUrls.uploadFile, formData)
}

export function tplToDownload(code) {
  const linkUrl = `${apiUrls.tplDownload}/${code}`
  const link = document.createElement('a');
  link.setAttribute('href', linkUrl)
  link.setAttribute('download', 'filename.xlsx'); // 设置下载文件名
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
  window.URL.revokeObjectURL(link);
  // const params = {
  //   code: code
  // }

  // return axios.get(`${apiUrls.tplDownload}/${code}`, {
  //   params: params
  // }).then(response => {
  //   console.log(response)
  //   const url = window.URL.createObjectURL(new Blob([response]));
  //   const link = document.createElement('a');
  //   link.setAttribute('href', url)
  //   link.setAttribute('download', 'filename.xlsx'); // 设置下载文件名
  //   document.body.appendChild(link);
  //   link.click();
  //   document.body.removeChild(link);
  //   window.URL.revokeObjectURL(url); // 清理内存
  // }).catch(err => {
  //   this.$message.error(err.message || '模板获取异常')
  // })
}
